using UnityEngine;

public class FlyCam : MonoBehaviour
{
	private float timer;

	private bool onDrag;

	private bool canDrag = true;

	private Vector3 offset;

	private Vector3 target;

	private Camera mainCamera;

	private Vector3 touchPosition;

	private Transform cacheTransform;

	[SerializeField]
	private float dragSpeed;

	[SerializeField]
	private float smoothTime;

	[SerializeField]
	private float cameraFixed;

	[SerializeField]
	private float pressedTime;

	[SerializeField]
	private float minPosition;

	[SerializeField]
	private float maxPosition;

	public bool CanDrag
	{
		set
		{
			canDrag = value;
		}
	}
    public void Awake()
    {
        AdManager1.instance.InitData();


    }
    private void Start()
	{
        AdManager1.instance.InitData();

        mainCamera = Camera.main;
		cacheTransform = base.transform;
		if (Mathf.Approximately(mainCamera.aspect, 0.75f))
		{
			mainCamera.orthographicSize = cameraFixed / 0.5625f;
		}
		else
		{
			mainCamera.orthographicSize = cameraFixed / mainCamera.aspect;
		}
	}

	private void Update()
	{
        if (Input.GetMouseButtonUp(0))
        {
            Reset();
        }
        if (!canDrag)
		{
			return;
		}
		if (!onDrag)
		{
			if (Input.GetMouseButtonDown(0))
			{
				touchPosition = mainCamera.ScreenToWorldPoint(UnityEngine.Input.mousePosition);
				timer = pressedTime;
			}
			if (timer > 0f)
			{
				timer -= Time.deltaTime;
				if (timer <= 0f)
				{
					onDrag = true;
				}
			}
		}
		if (onDrag && Input.GetMouseButton(0))
		{
			offset = mainCamera.ScreenToWorldPoint(UnityEngine.Input.mousePosition) - touchPosition;
			offset *= dragSpeed;
			Vector3 position = cacheTransform.position;
			float num = Mathf.Clamp(position.y - offset.y, minPosition, maxPosition);
			Vector3 position2 = cacheTransform.position;
			float x = position2.x;
			float y = num;
			Vector3 position3 = cacheTransform.position;
			target = new Vector3(x, y, position3.z);
		}
		if (Input.GetMouseButtonUp(0))
		{
			Reset();
		}
		if (target != Vector3.zero)
		{
			cacheTransform.position = Vector3.Lerp(cacheTransform.position, target, Time.deltaTime * smoothTime);
		}
	}

	private void Reset()
	{
		timer = 0f;
		onDrag = false;
		offset = (touchPosition = Vector3.zero);
	}
}
